package com.corpgovernment.organization.factory;

import com.corpgovernment.organization.service.IPassengerService;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

/**
 * @author jhxue
 * @create 2022-02-25-14:25
 */
@Component
public class PassengerServiceFactory {

	@Autowired
	private List<IPassengerService> passengerServices;

	private volatile Map<String, IPassengerService> passengerServiceMap;

	@PostConstruct
	private void init() {
		Map<String, IPassengerService> passengerServiceHashMap = Maps.newHashMapWithExpectedSize(passengerServices.size());
		for (IPassengerService passengerService : passengerServices) {
			passengerServiceHashMap.put(passengerService.getType(), passengerService);
		}
		passengerServiceMap = passengerServiceHashMap;
	}

	public IPassengerService getByType(String type){
		return passengerServiceMap.get(type);
	}
}
